
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">
	
	<ui:define name="headIncludes">
		<f:event listener="#{contaPagarBean.initializeForm(param.contaPagarId)}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">#{contaPagarBean.acao}</ui:define>
	<ui:define name="buttons">
		<p:commandButton value="Salvar" style="height:28px;" action="#{contaPagarBean.save}" rendered="#{contaPagarBean.currentConta.id == null}" update="@this" icon="ui-icon-disk"/>
		<p:commandButton value="Pagar" style="height:28px;" action="#{contaPagarBean.pagarContaPagar}"  rendered="#{contaPagarBean.currentConta.id != null and contaPagarBean.currentConta.status != 'PAGA'}" icon="ui-icon-check"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{contaPagarBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>			
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages closable="true" autoUpdate="true"/>
				
				<h:panelGrid columns="2" style="padding:5px;" id="panelFornecedorForm" rendered="#{contaPagarBean.currentConta.id == null}">
					<h:outputText value="Fornecedor *" />
					<h:outputText value="" />
					<p:autoComplete id="autoInputFornecedor" var="fornecedor" value="#{contaPagarBean.currentConta.fornecedor}"
						itemLabel="#{fornecedor.nome}" itemValue="#{fornecedor}" size="60" required="true" requiredMessage="Informe o fornecedor."
						converter="fornecedorConverter" completeMethod="#{contaPagarBean.getFornecedorByQuery}" maxlength="100">
					</p:autoComplete>
					<p:commandButton icon="ui-icon-search" style="height:24px;" immediate="true" actionListener="#{contaPagarBean.openDialogListFornecedor}" id="btSearchFornecedor" title="Selecionar fornecedor"/>	
				</h:panelGrid>
				
				<h:panelGrid columns="1" style="padding:5px;" rendered="#{contaPagarBean.currentConta.id != null}">
					<h:outputText style="padding:7px;" value="Fornecedor" />
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.fornecedor.nome}"/>
				</h:panelGrid>
				
				
				<h:panelGrid columns="5" style="padding:5px;" rendered="#{contaPagarBean.currentConta.id == null}">
					<h:outputText value="Nº do documento" />
					<h:outputText value="Descrição *" />
					<h:outputText value="Data de emissão *" />
					<h:outputText value="Valor *" />
					<h:outputText value="Data de vencimento *" />
					
					<p:inputText style="width:100px;" value="#{contaPagarBean.currentConta.id}" disabled="true"/>
					
					<p:inputText style="width:304px;" value="#{contaPagarBean.currentConta.descricao}" required="true" requiredMessage="Informe a descrição."
						disabled="#{contaPagarBean.currentConta.id != null}" maxlength="50"/>
						
					<p:calendar value="#{contaPagarBean.currentConta.dataEmissao}" navigator="true" id="inputDataEmissao" required="true" requiredMessage="Informe a data de emissão."
						readonlyInput="true" showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" maxdate="#{contaPagarBean.maxDate}" disabled="#{contaPagarBean.currentConta.id != null}">
						<p:ajax event="dateSelect" listener="#{contaPagarBean.handleDateSelected}"/>
					</p:calendar>
					
					<pe:inputNumber style="width:100px;" value="#{contaPagarBean.currentConta.valor}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." disabled="#{contaPagarBean.currentConta.id != null}">
						<p:ajax event="blur" listener="#{contaPagarBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<p:calendar style="width:100px;" value="#{contaPagarBean.currentConta.dataVencimento}" 
						navigator="true" id="inputDataVencimento" required="true" requiredMessage="Informe a data de vencimento." 
						disabled="#{contaPagarBean.currentConta.id != null}"
						readonlyInput="true" showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" 
						mindate="#{contaPagarBean.currentConta.dataEmissao == null ? contaPagarBean.maxDate : contaPagarBean.currentConta.dataEmissao}">
					</p:calendar>
					
				</h:panelGrid>
				
				<h:panelGrid columns="5" style="padding:5px;" rendered="#{contaPagarBean.currentConta.id != null}">
					<h:outputText style="padding:7px;" value="Nº do documento" />
					<h:outputText style="padding:7px;" value="Descrição" />
					<h:outputText style="padding:7px;" value="Data de emissão" />
					<h:outputText style="padding:7px;" value="Valor" />
					<h:outputText style="padding:7px;" value="Data de vencimento" />
					
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.id}"/>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.descricao}"/>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.dataEmissao}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.valor}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.dataVencimento}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="6" style="padding:5px;">
					<h:outputText value="Multa (R$)" />
					<h:outputText value="Juros (%)" />
					<h:outputText value="Desconto (R$)" />
					<h:outputText value="Desconto (%)" />
					<h:outputText value="Data de pagamento" />
					<h:outputText value="Valor total"/>

					<pe:inputNumber style="width:100px;" value="#{contaPagarBean.currentConta.multa}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputMulta" maxValue="1000000"
						disabled="#{(contaPagarBean.currentConta.descontoValor != null and contaPagarBean.currentConta.descontoValor > 0) 
										or (contaPagarBean.currentConta.descontoPercentual != null and contaPagarBean.currentConta.descontoPercentual > 0)}">
						<p:ajax event="change" update="inputDescontoValor, inputDescontoPercent" listener="#{contaPagarBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaPagarBean.currentConta.juros}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputJuros" 
						disabled="#{(contaPagarBean.currentConta.descontoValor != null and contaPagarBean.currentConta.descontoValor > 0) 
										or (contaPagarBean.currentConta.descontoPercentual != null and contaPagarBean.currentConta.descontoPercentual > 0)}"
						maxValue="100">
						<p:ajax event="change" update="inputDescontoValor, inputDescontoPercent" listener="#{contaPagarBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaPagarBean.currentConta.descontoValor}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputDescontoValor" maxValue="1000000"
						disabled="#{(contaPagarBean.currentConta.multa != null and contaPagarBean.currentConta.multa > 0) 
										or (contaPagarBean.currentConta.juros != null and contaPagarBean.currentConta.juros > 0)
										or (contaPagarBean.currentConta.descontoPercentual != null and contaPagarBean.currentConta.descontoPercentual > 0)}">
						<p:ajax event="change" update="inputDescontoPercent, inputMulta, inputJuros" listener="#{contaPagarBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaPagarBean.currentConta.descontoPercentual}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputDescontoPercent"
						disabled="#{(contaPagarBean.currentConta.multa != null and contaPagarBean.currentConta.multa > 0) 
										or (contaPagarBean.currentConta.juros != null and contaPagarBean.currentConta.juros > 0)
										or (contaPagarBean.currentConta.descontoValor != null and contaPagarBean.currentConta.descontoValor > 0)}"
						maxValue="100">
						<p:ajax event="change" update="inputDescontoValor, inputMulta, inputJuros" listener="#{contaPagarBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<p:calendar style="width:100px;" showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" navigator="true" readonlyInput="true"
						value="#{contaPagarBean.currentConta.dataPagamento}" id="inputDataPagamento" 
						mindate="#{contaPagarBean.currentConta.dataEmissao == null ? contaPagarBean.maxDate : contaPagarBean.currentConta.dataEmissao}"/>	
									
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.valorPago}" id="inputValorPago">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					
				</h:panelGrid>
				
				<h:panelGrid>
					<h:outputText value="* Campos obrigatórios" />
				</h:panelGrid>
			</div>
		</p:panel>		
	</ui:define>
	<ui:define name="popups">
		<ui:include src="listFornecedor.xhtml"/>
		<ui:include src="formFornecedor.xhtml"/>
	</ui:define>
</ui:composition>